package com.training.java.core.collections.car.post15;

import java.security.KeyStore.Entry;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapEntrySetDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Map<String, String> directory = new HashMap<String, String>();

		directory.put("Satya", "972 506 7885");
		directory.put("Satish", "469 371 2366");
		directory.put("Vijaya", "972 869 0042");
		directory.put("Rupa", "972 550 0208");
		directory.put("Rupa", "972 550 0208");// duplicate entry

		// Print Rupa key's values
		System.out
				.println("************************************************* ");

		System.out.println("What is Rupa's Phone number ?:  "
				+ directory.get("Rupa"));

		System.out
				.println("************************************************* ");

		/**
		 * 
		 * There are 2 ways to print all keys and values. One way:Get all keys
		 * first and ask everyone's value. Using Set,KeySet-- which gives set of
		 * keys. Using for each loop to print the keys and values. Another way
		 * is Entry Set.
		 */

		/**
		 * Entry set is more intutive way of getting the Key and value. First
		 * get the whole entry and leter ask the Entry to get the value.
		 */

		Set<Map.Entry<String, String>> entries = directory.entrySet();

		for (Map.Entry<String, String> entry : entries) {

			String key = entry.getKey();
			String value = entry.getValue();

			System.out.println("Key is =  " + key + "   Value  =  " + value);

		}

		System.out.println("***************************************");
	}

	/*
	 * //Method#1 to get the key and value.
	 * 
	 * Set<String> keys = directory.keySet(); // Taking Set of key in to
	 * variable Keys.
	 * 
	 * 
	 * 
	 * for(String eachKey : keys) {
	 * 
	 * String value = directory.get(eachKey);//Declaring "value" variable to
	 * store the value of get(eachKey)
	 * 
	 * System.out.println("Keys = "+eachKey+" Value= "+value);
	 * 
	 * }
	 * 
	 * System.out.println("************************************************* ");
	 * 
	 * 
	 * }
	 */
}
